package cn.edu.sdjzu.xg.eagle.service;

import cn.edu.sdjzu.xg.eagle.dao.UserDaoImpl;
import cn.edu.sdjzu.xg.eagle.dao.UserDaoInterface;
import cn.edu.sdjzu.xg.eagle.entity.User;
import cn.edu.sdjzu.xg.eagle.factory.DaoFactory;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;



public class UserServiceImpl implements UserServiceInterface{
    private UserDaoInterface userDao = DaoFactory.getDao(UserDaoImpl.class,"UserDaoImpl");
    private static UserServiceImpl userServiceImpl = new UserServiceImpl();
    private UserServiceImpl() {
    }
    public static UserServiceImpl getInstance() {
        return userServiceImpl;
    }
    public boolean add(User user, Connection connection) throws SQLException {
        return UserDaoImpl.getInstance().add(user, connection);


    }
    public boolean delete(User user, Connection connection) throws SQLException {
        return UserDaoImpl.getInstance().delete(user, connection);
    }
    @Override
    public void login(User userToLogin) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        userDao.login(connection,userToLogin);
        JdbcHelper.close(connection);
    }

}
